# 请从此处启动计算器！

tag_dict = {"colorama_import": True, "time_import": True, "others_import": True}

error_tag = 0

try:
    from colorama import Fore,  init
except ImportError:
    tag_dict["colorama_import"] = False

try:
    import time
except ImportError:
    tag_dict["time_import"] = False

try:
    from Function import _main
except ImportError:
    tag_dict["others_import"] = False

init(autoreset=True)

for i in range(0, 4):
    print("循环次数：" + Fore.GREEN + str(i) + Fore.RESET + "/" + Fore.YELLOW + str(4) + Fore.RESET)
    if not tag_dict["colorama_import"]:
        print("colorama模块导入失败，\n请检查您的电脑中是否安装了colorama库！")
        input("输入任意内容以关闭计算器……")
        break
    elif not tag_dict["time_import"]:
        print("time模块导入失败，\n照理说这不应该发生。\n请向其他人寻求帮助！")
        input("输入任意内容以关闭计算器……")
        break
    elif not tag_dict["others_import"]:
        print("计算器本体模块导入失败，\n请确保您完整获取了计算器！")
        input("输入任意内容以关闭计算器……")
        break
    else:
        print("环境检测完毕，计算器可以运行！\n静候五秒之后计算器将启动！")
        start_tag = True
        time.sleep(5)

        try:
            error_tag = _main.main(0, start_tag)
        except ValueError:
            print(Fore.RED + _main.error_name + Fore.YELLOW + "\n请输入一个[整形]数字！")
            print(Fore.RED + _main.error_name + Fore.YELLOW + _main.error_restart)
            time.sleep(2)
            continue
        except SyntaxError:
            print(Fore.RED + _main.error_name + Fore.YELLOW + "\n似乎程序的代码书写出现了一些问题……")
            print(Fore.RED + _main.error_name + Fore.YELLOW + _main.error_restart)
            time.sleep(2)
            continue
        except ZeroDivisionError:
            print(Fore.RED + _main.error_name + Fore.YELLOW + "\n请不要把[数字0]放在被除数上吖！")
            print(Fore.RED + _main.error_name + Fore.YELLOW + _main.error_restart)
            time.sleep(2)
            continue
        except KeyboardInterrupt:
            print(Fore.RED + _main.error_name + Fore.YELLOW + "\n您正在尝试退出计算器……")
            print(Fore.RED + _main.error_name + Fore.YELLOW + "很快，计算器就会正常退出……")
            time.sleep(2)
            break
        else:
            print(Fore.GREEN + "非常感谢您的使用！")
            break


print("Exit in 5 seconds...")
time.sleep(3)
print("Bye Bye !")
time.sleep(2)
exit(error_tag)
